home *** CD-ROM | disk | FTP | other *** search
/ Programmers Heaven 2 / Programmers Heaven 2.iso / files / graphics / library / wgt51_r2.zip / WGT5 / SRC / WSPR.C < prev   
Encoding:
C/C++ Source or Header  |  1996-08-03  |  17.6 KB  |  717 lines

  1. #include <stdlib.h>
  2. #include <string.h>
  3. #include <stdio.h>
  4. #include <wgt5.h>
  5. /*
  6. m
  7. ╔═════════════════════════════════════════════════════════════════╗
  8. ║             █▓▒░ WordUp Graphics Toolkit V5.0 ░▒▓█              ║
  9. ║    Source Code    Copyright 1995 Egerter Software               ║
  10. ╟─────────────────────────────────────────────────────────────────╢
  11. ║ Module:       spr.c                                             ║
  12. ║                                                                 ║
  13. ║ Last Revised: March 31, 1995                                    ║
  14. ║                                                                 ║
  15. ║ Written by:   Chris Egerter             WATCOM PROTECTED MODE!  ║
  16. ╚═════════════════════════════════════════════════════════════════╝
  17. */
  18.  
  19. static struct {
  20.   char patch_id[8];
  21.   char fname[12];
  22.   float version;
  23. } patch_struct = {"WGTPATCH", "wspr", 1.0} ;
  24.  
  25.  
  26. /* The following defines should be altered to suit your program needs */
  27. #define MAX_SPRITES        100
  28. #define MAX_ANIMATION      40
  29. #define MAX_MOVE           15
  30.  
  31. typedef struct
  32.  {
  33.   unsigned char num;          /* Sprite number shown */
  34.   short x, y;                 /* Coordinates on screen */
  35.   unsigned char on;           /* On/Off, for visibility */
  36.  
  37.   int ox, oy, ox2, oy2;
  38.  
  39.   signed char animon;                      /* Animation on/off */
  40.   short animation_images[MAX_ANIMATION];   /* Animation numbers */
  41.   unsigned char animation_speeds[MAX_ANIMATION]; /* Animation speeds */
  42.   signed char current_animation;           /* Current animation counter */
  43.   unsigned char animation_count;           /* Delay count for animation */
  44.  
  45.   signed char movex_on;                    /* X movement on/off */
  46.   short movex_distance[MAX_MOVE];          /* X distance per frame */
  47.   short movex_number[MAX_MOVE];            /* Number of times to move */
  48.   unsigned char movex_speed[MAX_MOVE];     /* Delay between each movement */
  49.   signed char current_movex;               /* Movement index */
  50.   short current_movex_number;              /* Number of times moved */
  51.   unsigned char movex_count;               /* Delay count for X movement */
  52.  
  53.   signed char movey_on;                    /* Y movement on/off */
  54.   short movey_distance[MAX_MOVE];          /* Y distance per frame */
  55.   short movey_number[MAX_MOVE];            /* Number of times to move */
  56.   unsigned char movey_speed[MAX_MOVE];     /* Delay between each movement */
  57.   signed char current_movey;               /* Movement index */
  58.   short current_movey_number;              /* Number of times moved */
  59.   unsigned char movey_count;               /* Delay count for Y movement */
  60.  } sprite_object;
  61.  
  62. sprite_object s[MAX_SPRITES];
  63.  
  64. block backgroundscreen = NULL;          /* Holds the constant background */
  65. block spritescreen = NULL;              /* Work buffer */
  66.  
  67. short maxsprite;
  68.  
  69. int tempx1, tempy1, tempx2, tempy2;
  70.  
  71. block *sprite_images;
  72.  
  73.  
  74. void spriteon (short number, short x, short y, short image);
  75. void spriteoff (short number);
  76.  
  77. void draw_sprites (int movement_multiplier);
  78. void initialize_sprites (block *sprite_blocks);
  79. void deinitialize_sprites (void);
  80. void erase_sprites (void);
  81.  
  82. void animate (short spnum, char *str);
  83. void animon (short spnum);
  84. void animoff (short spnum);
  85. void movex (short spnum, char *str);
  86. void movey (short spnum, char *str);
  87. void movexon (short spnum);
  88. void movexoff (short spnum);
  89. void moveyon (short spnum);
  90. void moveyoff (short spnum);
  91. short overlap (short s1, short s2);
  92.  
  93.  
  94. void expand_dirty_rectangle (int sprite_num, int x, int y, int x2, int y2);
  95. void copy_sprites (void);
  96.  
  97.  
  98. void spriteon (short number, short x, short y, short image)
  99. /* Turns a sprite on at (x,y), with sprites[image] */
  100. {
  101.  
  102.  tempx1 = x;
  103.  tempy1 = y;
  104.  tempx2 = x + wgetblockwidth (sprite_images[image]);
  105.  tempy2 = y + wgetblockheight (sprite_images[image]);
  106.  
  107.  /* Find the update box */
  108.  if (tempx1 < tx)                       /* X1 */
  109.      tempx1 = tx;
  110.  else
  111.  if (tempx1 >= WGT_SYS.xres)
  112.      tempx1  = WGT_SYS.xres - 1;
  113.  
  114.  if (tempy1 < ty)                       /* Y1 */
  115.      tempy1 = ty;
  116.  else
  117.  if (tempy1 >= WGT_SYS.yres)
  118.      tempy1  = WGT_SYS.yres - 1;
  119.  
  120.  if (tempx2 < tx)                       /* X2 */
  121.      tempx2 = tx;
  122.  else
  123.  if (tempx2 >= WGT_SYS.xres)
  124.      tempx2  = WGT_SYS.xres - 1;
  125.  
  126.  if (tempy2 < ty)                       /* Y2 */
  127.      tempy2 = ty;
  128.  else
  129.  if (tempy2 >= WGT_SYS.yres)
  130.      tempy2  = WGT_SYS.yres - 1;
  131.  
  132.  s[number].x = x;               /* Set up the coords */
  133.  s[number].y = y;
  134.  s[number].num = image;
  135.  s[number].on = 1;
  136.  
  137.  s[number].ox = tempx1;         /* Set the dirty rectangle location */
  138.  s[number].oy = tempy1;
  139.  s[number].ox2 = tempx2;
  140.  s[number].oy2 = tempy2;
  141. }
  142.  
  143.  
  144.  
  145. void spriteoff (short number)
  146. /* Turns a sprite off */
  147. {
  148.  if (s[number].on == 1)
  149.      s[number].on = 2;     /* Signals sprite is to be taken off */
  150. }
  151.  
  152.  
  153.  
  154. void erase_sprites (void)
  155. /* Erases all sprites from background screen by copying the dirty
  156.    rectangles */
  157. {
  158. short i;
  159. block curscreen;
  160. short osx, osy;
  161.  
  162. sprite_object *spriteptr;
  163. int x, y, x2, y2;
  164.  
  165. curscreen = abuf;
  166. osx = WGT_SYS.xres;
  167. osy = WGT_SYS.yres;
  168.  
  169.  wsetscreen (spritescreen);         /* Go to background screen */
  170.  
  171.  spriteptr = s;
  172.  
  173.  for (i = 0; i <= maxsprite; i++)   /* Loop through all sprites */
  174.   {
  175.    if (spriteptr->on == 1)           /* If sprite is on */
  176.      {
  177.       x = spriteptr->ox;      /* Get the old dirty rectangle coordinates */
  178.       y = spriteptr->oy;
  179.       x2 = spriteptr->ox2;
  180.       y2 = spriteptr->oy2;
  181.  
  182.       if (x < tx)           /* Clip them, but don't change the original */
  183.       x = tx;           /* values, because we need them later */
  184.       else if (x > bx)
  185.       x = bx;
  186.       if (y < ty)
  187.       y = ty;
  188.       else if (y > by)
  189.       y = by;
  190.  
  191.       wcopyscreen (x, y, x2, y2, backgroundscreen, x, y, spritescreen);
  192.      }
  193.      spriteptr++;   /* Next sprite */
  194.   }
  195.  
  196.  abuf = curscreen;
  197.  WGT_SYS.xres = osx;
  198.  WGT_SYS.yres = osy;
  199. }
  200.  
  201.  
  202.  
  203. void expand_dirty_rectangle (int sprite_num, int x, int y, int x2, int y2)
  204. /* Find boundaries of the old and new sprite rectangle */
  205. {
  206. sprite_object *spriteptr;
  207.  
  208.  spriteptr = &s[sprite_num];
  209.  
  210.  if (x < tempx1)                /* Compare with */
  211.      tempx1 = x;
  212.  if (x2 > tempx2)
  213.      tempx2 = x2;
  214.  if (y < tempy1)
  215.      tempy1 = y;
  216.  if (y2 > tempy2)
  217.      tempy2 = y2;
  218.  
  219.  if (tempx1 < tx)                   /* Compare with clipping boundaries */
  220.      tempx1 = tx;
  221.  
  222.  if (tempx2 > bx)
  223.      tempx2 = bx;
  224.  
  225.  if (tempy1 < ty)
  226.      tempy1 = ty;
  227.  
  228.  if (tempy2 > by)
  229.      tempy2 = by;
  230. }
  231.  
  232.  
  233. void copy_sprites (void)
  234. {
  235. int i;
  236. sprite_object *spriteptr;
  237. int x, y, x2, y2;
  238.  
  239.   spriteptr = s;
  240.   for (i = 0; i <= maxsprite; i++)
  241.    {
  242.     if (spriteptr->on > 0)             /* If sprite is on */
  243.     {
  244.      if (spriteptr->on == 2) 
  245.      spriteptr->on = 0;
  246.      
  247.  
  248.      /* Store these values because they are used more than once */
  249.      x  = spriteptr->x;
  250.      y  = spriteptr->y;
  251.      x2 = x + wgetblockwidth (sprite_images[spriteptr->num]) - 1;
  252.      y2 = y + wgetblockheight (sprite_images[spriteptr->num]) - 1;
  253.  
  254.      /* Set the dirty rectangle to the current position of the sprite */
  255.      tempx1 = x;
  256.      tempy1 = y;
  257.      tempx2 = x2;
  258.      tempy2 = y2;
  259.  
  260.      expand_dirty_rectangle (i, spriteptr->ox, spriteptr->oy,
  261.                 spriteptr->ox2, spriteptr->oy2);
  262.  
  263.      wcopyscreen (tempx1, tempy1, tempx2, tempy2, spritescreen, tempx1, tempy1, 
  264.           NULL);
  265.  
  266.      spriteptr->ox = x;
  267.      spriteptr->oy = y;
  268.      spriteptr->ox2 = x2;
  269.      spriteptr->oy2 = y2;
  270.  
  271.     }
  272.     spriteptr++;
  273.    }
  274. }
  275.  
  276.  
  277.  
  278.  
  279. void draw_sprites (int movement_multiplier)
  280. /* Draw the sprites on the sprite screen */
  281. {
  282. short i;
  283. int size;
  284. block curscreen;
  285. short osx, osy;
  286. sprite_object *spriteptr;
  287. int move;
  288.  
  289.  curscreen = abuf;
  290.  osx = WGT_SYS.xres;
  291.  osy = WGT_SYS.yres;
  292.  
  293.  wsetscreen (spritescreen);  /* Go to sprite screen */
  294.  
  295.  
  296.  for (move = 0; move < movement_multiplier; move++)
  297.  {
  298.   spriteptr = s;
  299.   for (i = 0; i <= maxsprite; i++)      /* Loop through all sprites */
  300.   {
  301.     if (spriteptr->on == 1)             /* If sprite is on */
  302.     {
  303.       if (spriteptr->movex_on == 1)      /* X movement on */
  304.       {
  305.     if (spriteptr->movex_count != 0)/* Delay Count not reached 0? */
  306.       spriteptr->movex_count--;     /* Decrease count */
  307.     else                            /* Get the next move */
  308.     {
  309.       spriteptr->current_movex_number++; /* Increase # of times moved */
  310.       if (spriteptr->current_movex_number ==
  311.           spriteptr->movex_number[spriteptr->current_movex])
  312.            /* Moved the right number of times yet? */
  313.         {
  314.          spriteptr->current_movex++; /* Increase ptr in move array */
  315.          if (spriteptr->movex_number[spriteptr->current_movex] == - 1)
  316.         /* Repeat move */
  317.         spriteptr->current_movex = 0;
  318.         else if (spriteptr->movex_number[spriteptr->current_movex]
  319.              == - 2) /* End move */
  320.         {
  321.           spriteptr->current_movex--;
  322.           spriteptr->movex_on = 0; /* Turn off movement */
  323.         }
  324.         spriteptr->current_movex_number = 0;
  325.           /* Reset number of times moved */
  326.       }
  327.       spriteptr->movex_count = spriteptr->movex_speed
  328.           [spriteptr->current_movex]; /* Get delay */
  329.       spriteptr->x += spriteptr->movex_distance
  330.           [spriteptr->current_movex];      /* Update X coord */
  331.     }
  332.       }
  333.  
  334.  
  335.       if (spriteptr->movey_on == 1)      /* Y movement on */
  336.       {
  337.     if (spriteptr->movey_count != 0)/* Delay Count not reached 0? */
  338.       spriteptr->movey_count--;     /* Decrease count */
  339.     else                            /* Get the next move */
  340.     {
  341.       spriteptr->current_movey_number++; /* Increase # of times moved */
  342.       if (spriteptr->current_movey_number ==
  343.           spriteptr->movey_number[spriteptr->current_movey])
  344.            /* Moved the right number of times yet? */
  345.         {
  346.          spriteptr->current_movey++; /* Increase ptr in move array */
  347.          if (spriteptr->movey_number[spriteptr->current_movey] == - 1)
  348.         /* Repeat move */
  349.         spriteptr->current_movey = 0;
  350.         else if (spriteptr->movey_number[spriteptr->current_movey]
  351.              == - 2) /* End move */
  352.         {
  353.           spriteptr->current_movey--;
  354.           spriteptr->movey_on = 0; /* Turn off movement */
  355.         }
  356.         spriteptr->current_movey_number = 0;
  357.           /* Reset number of times moved */
  358.       }
  359.       spriteptr->movey_count = spriteptr->movey_speed
  360.           [spriteptr->current_movey]; /* Get delay */
  361.       spriteptr->y += spriteptr->movey_distance
  362.           [spriteptr->current_movey];      /* Update Y coord */
  363.     }
  364.       }
  365.  
  366.  
  367.  
  368.       if (spriteptr->animon == 1)             /* update animation */
  369.       {
  370.     if (spriteptr->animation_count != 0)  /* Delay count at 0? */
  371.       spriteptr->animation_count--;       /* No, so decrease by one. */
  372.     else    /* Otherwise animate the sprite */
  373.     {
  374.       spriteptr->current_animation++;     /* Increase animation ptr */
  375.       if (spriteptr->animation_images[spriteptr->current_animation]
  376.         == - 1) /* Repeat animation */
  377.         spriteptr->current_animation = 0;
  378.  
  379.       if (spriteptr->animation_images[spriteptr->current_animation]
  380.         == - 2) /* End animation */
  381.       {
  382.         spriteptr->current_animation--;
  383.         spriteptr->animon = 0;  /* Turn off animation */
  384.       }
  385.  
  386.       spriteptr->num = spriteptr->animation_images
  387.         [spriteptr->current_animation]; /* Change sprite number */
  388.       spriteptr->animation_count = spriteptr->animation_speeds
  389.         [spriteptr->current_animation]; /* Reset delay count */
  390.     }
  391.       }
  392.  
  393.     }
  394.    spriteptr++;
  395.   }
  396.  }
  397.  
  398.  
  399.   for (i = 0; i <= maxsprite; i++)      /* Loop through all sprites */
  400.    if ((s[i].on == 1) && (sprite_images[ s[i].num ] != NULL))
  401.      wputblock (s[i].x, s[i].y, sprite_images[ s[i].num ], 1);
  402.  
  403.   abuf = curscreen;
  404.   WGT_SYS.xres = osx;
  405.   WGT_SYS.yres = osy;
  406.   copy_sprites ();
  407. }
  408.  
  409.  
  410.  
  411.  
  412.  
  413. void initialize_sprites (block *sprite_blocks)
  414. /* Set up everything for the sprite engine */
  415. {
  416. short i;
  417.  
  418.  maxsprite = MAX_SPRITES - 1;
  419.  
  420.  sprite_images = sprite_blocks;
  421.  
  422.  for (i = 0; i < MAX_SPRITES; i++)    /* Turn off the sprites */
  423.    s[i].on = 0;
  424.  
  425.  
  426.  if (spritescreen == NULL)
  427.      spritescreen = wnewblock (0, 0, WGT_SYS.xres - 1, WGT_SYS.yres - 1);
  428.     /* Make a virtual screen for the work buffer */
  429.  
  430.  if (backgroundscreen == NULL)
  431.      backgroundscreen = wnewblock (0, 0, WGT_SYS.xres - 1, WGT_SYS.yres - 1);
  432.     /* Make a virtual screen for the background screen */
  433.  
  434. }
  435.  
  436.  
  437.  
  438. void deinitialize_sprites (void)
  439. {
  440. short i;
  441.  
  442.  for (i = 0; i < MAX_SPRITES; i++)
  443.    s[i].on = 0;
  444.  
  445.   wfreeblock (spritescreen);
  446.   spritescreen = NULL;
  447.  
  448.   wfreeblock (backgroundscreen);
  449.   backgroundscreen = NULL;
  450. }
  451.  
  452.  
  453.  
  454. void animate (short spnum, char *str)
  455. /* Parse animation string and put the data into an array */
  456. {
  457. short c, temp1;
  458. short x, in, len, minus;
  459. short change;
  460.  
  461.   s[spnum].current_animation = 0; /* Reset current animation ptr */
  462.   s[spnum].animation_count = s[spnum].animation_speeds[
  463.     s[spnum].current_animation]; /* Reset delay count */
  464.  
  465.   x = 0;
  466.   in = 0;
  467.  
  468.   len = strlen (str);
  469.  
  470.   /* Parse animation string */
  471.  
  472.   do {
  473.  
  474.       do {/* Find the first bracket */
  475.       c = str[x];
  476.       x++;
  477.      } while (c != '(');
  478.  
  479.       change = 0;
  480.       do {
  481.       temp1 = 0;
  482.       minus = 0;
  483.       do {
  484.           c = str[x];
  485.           if ((c != ',') && (c != 'R') && (c != '-') && (c != ')'))
  486.            temp1 = (temp1 * 10) + (c - 48);
  487.           if (c == '-')
  488.           minus = 1;
  489.           x++;
  490.          } while ((x != len) && (c != ',') && (c != 'R') && (c != ')'));
  491.  
  492.       if (minus == 1)
  493.           temp1 = - temp1;
  494.       if (change == 0)
  495.           s[spnum].animation_images[in] = temp1;
  496.       else
  497.           s[spnum].animation_speeds[in] = temp1;
  498.       change++;
  499.      } while (c != ')'); /* Until the last bracket */
  500.  
  501.       in++;
  502.       if (in >= MAX_ANIMATION)
  503.       in = MAX_ANIMATION-1;
  504.  
  505.       s[spnum].animation_images[in] = - 2;
  506.  
  507.       c = str[x];
  508.       if (c == 'R')
  509.     {
  510.      x = len;
  511.      s[spnum].animation_images[in] = - 1;
  512.     }
  513.      } while (x != len);
  514. }
  515.  
  516.  
  517. void animon (short spnum)
  518. /* Turns animation for a sprite on */
  519. {
  520.     s[spnum].animon = 1;
  521. }
  522.  
  523.  
  524. void animoff (short spnum)
  525. /* Turns animation for a sprite off */
  526. {
  527.     s[spnum].animon = 0;
  528. }
  529.  
  530.  
  531. /* X movements */
  532.  
  533. void movexon (short spnum)
  534. /* Turns a sprite's x movement on */
  535. {
  536.     s[spnum].movex_on = 1;
  537. }
  538.  
  539.  
  540. void movexoff (short spnum)
  541. /* Turns a sprite's x movement off */
  542. {
  543.     s[spnum].movex_on = 0;
  544. }
  545.  
  546.  
  547. void movex (short spnum, char *str)
  548. /* Parses a movement string and places data into movement arrays */
  549. {
  550. short c, temp1;
  551. short x, in, len, minus;
  552. short change;
  553.  
  554.   s[spnum].current_movex = 0;  /* First x movement */
  555.   s[spnum].movex_count = s[spnum].movex_speed[s[spnum].current_movex];
  556.   s[spnum].current_movex_number = 0;   /* First time it moved */
  557.  
  558.   x = 0;
  559.   in = 0;
  560.  
  561.   len = strlen (str);
  562.  
  563.   do {
  564.       do {
  565.       c = str[x];
  566.       x++;
  567.      } while (c != '(');
  568.       change = 0;
  569.  
  570.       do {
  571.       temp1 = 0;
  572.       minus = 0;
  573.       do {
  574.           c = str[x];
  575.           if ((c != ',') && (c != 'R') && (c != '-') && (c != ')'))
  576.           temp1 = (temp1*10) + (c - 48);
  577.           if (c == '-')
  578.           minus = 1;
  579.           x++;
  580.          } while ((x != len) && (c != ',') && (c != 'R') && (c != ')'));
  581.  
  582.       if (minus == 1)
  583.          temp1 = - temp1;
  584.       if (change == 0)
  585.          s[spnum].movex_distance[in] = temp1;
  586.       else if (change == 1)
  587.          s[spnum].movex_number[in] = temp1;
  588.       else
  589.          s[spnum].movex_speed[in] = temp1;
  590.  
  591.       change++;
  592.      } while (c != ')');
  593.     in++;
  594.  
  595.     if (in == MAX_MOVE)
  596.         x = len;
  597.     s[spnum].movex_number[in] = - 2;
  598.     c = str[x];
  599.     if (c == 'R')
  600.     {
  601.         x = len;
  602.         s[spnum].movex_number[in] = - 1;
  603.     }
  604.     } while (x != len);
  605.  
  606. }
  607.  
  608.  
  609.  
  610.  
  611. /* Y movements */
  612.  
  613. void moveyon (short spnum)
  614. /* Turns a sprite's y movement on */
  615. {
  616.     s[spnum].movey_on = 1;
  617. }
  618.  
  619.  
  620. void moveyoff (short spnum)
  621. /* Turns a sprite's y movement off */
  622. {
  623.     s[spnum].movey_on = 0;
  624. }
  625.  
  626.  
  627. void movey (short spnum, char *str)
  628. /* Parses a movement string and places data into movement arrays */
  629. {
  630. short c, temp1;
  631. short x, in, len, minus;
  632. short change;
  633.  
  634.   s[spnum].current_movey = 0;  /* First x movement */
  635.   s[spnum].movey_count = s[spnum].movey_speed[s[spnum].current_movey];
  636.   s[spnum].current_movey_number = 0;   /* First time it moved */
  637.  
  638.   x = 0;
  639.   in = 0;
  640.  
  641.   len = strlen (str);
  642.  
  643.   do {
  644.       do {
  645.       c = str[x];
  646.       x++;
  647.      } while (c != '(');
  648.       change = 0;
  649.  
  650.       do {
  651.       temp1 = 0;
  652.       minus = 0;
  653.       do {
  654.           c = str[x];
  655.           if ((c != ',') && (c != 'R') && (c != '-') && (c != ')'))
  656.           temp1 = (temp1*10) + (c - 48);
  657.           if (c == '-')
  658.           minus = 1;
  659.           x++;
  660.          } while ((x != len) && (c != ',') && (c != 'R') && (c != ')'));
  661.  
  662.       if (minus == 1)
  663.          temp1 = - temp1;
  664.       if (change == 0)
  665.          s[spnum].movey_distance[in] = temp1;
  666.       else if (change == 1)
  667.          s[spnum].movey_number[in] = temp1;
  668.       else
  669.          s[spnum].movey_speed[in] = temp1;
  670.  
  671.       change++;
  672.      } while (c != ')');
  673.     in++;
  674.  
  675.     if (in == MAX_MOVE)
  676.         x = len;
  677.     s[spnum].movey_number[in] = - 2;
  678.     c = str[x];
  679.     if (c == 'R')
  680.     {
  681.         x = len;
  682.         s[spnum].movey_number[in] = - 1;
  683.     }
  684.     } while (x != len);
  685.  
  686. }
  687.  
  688.  
  689.  
  690. short overlap (short s1, short s2)
  691. /* Tests if two sprites overlap
  692.    Not pixel precise, just checks rectangles */
  693. {
  694. short n1, n2;
  695. short width1, height1;
  696. short width2, height2;
  697.  
  698.  if ((s[s2].on == 1) && (s[s1].on == 1)) // Make sure both are on
  699.    {
  700.     n1 = s[s1].num; // For easier reading
  701.     n2 = s[s2].num;
  702.  
  703.     width1 = wgetblockwidth (sprite_images[n1]);
  704.     width2 = wgetblockwidth (sprite_images[n2]);
  705.     height1 = wgetblockheight (sprite_images[n1]);
  706.     height2 = wgetblockheight (sprite_images[n2]);
  707.  
  708.     if (( s[s2].x >= s[s1].x - width2 ) &&
  709.     ( s[s2].x <= s[s1].x + width1 ) &&
  710.     ( s[s2].y >= s[s1].y - height2 ) &&
  711.     ( s[s2].y <= s[s1].y + height1 ))
  712.     return 1; /* Collision! */
  713.     }
  714.     return 0; /* No collision */
  715. }
  716.  
  717.